package member.base.action;

import m.common.action.ActionRequest;
import m.common.action.Param;
import m.common.action.RequestMethod;
import m.common.model.util.*;
import m.system.util.JSONMessage;
import member.base.model.MemberLevel;
import member.base.model.UserInfo;
import member.base.util.PowerUtil;

@ActionRequest(name = "action/base/memberLevel",description = "会员级别")
public class MemberLevelAction extends BaseAction{

    @RequestMethod(description = "列表")
    public JSONMessage getList() throws Exception {
        ModelQueryList queryList=toQueryList(MemberLevel.class,"*");
        queryList.addCondition(QueryCondition.eq("business.oid", PowerUtil.getBusiness().getOid()));
        return JSONMessage.success("查询成功").push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @RequestMethod(description = "保存")
    public JSONMessage save(@Param("model") MemberLevel model) throws Exception {
        PowerUtil.verifyPower(UserInfo.PowerManage);
        model.setBusiness(PowerUtil.getBusiness());
        ModelQueryCheck.init(model)
            .checkNotNull("color","颜色不能为空")
            .checkNotNull("name","名称不能为空")
            .checkNotNull("discount","优惠折扣不能为空")
            .doCheck(false,true);
        ModelCheckUtil.checkUniqueCombine(model,new String[]{"business.oid","name"},"名称已存在");
        ModelUpdateUtil.saveModel(model);
        return JSONMessage.success("保存成功");
    }
}
